package com.sjtu.vfact.visualization.base;

import com.sjtu.vfact.visualization.view.GraphFrame;

import edu.uci.ics.jung.algorithms.layout.CircleLayout;
import edu.uci.ics.jung.algorithms.layout.FRLayout;
import edu.uci.ics.jung.algorithms.layout.FRLayout2;
import edu.uci.ics.jung.algorithms.layout.KKLayout;
import edu.uci.ics.jung.algorithms.layout.Layout;
import edu.uci.ics.jung.algorithms.layout.SpringLayout;
import edu.uci.ics.jung.algorithms.layout.SpringLayout2;
import edu.uci.ics.jung.graph.Graph;

public enum LAYOUT {
	
	FRLAYOUT("FRLayout", FRLayout.class),
	FRLAYOUT2("FRLayout2", FRLayout2.class),
	CIRCLELAYOUT("CircleLayout", CircleLayout.class),
	KKLAYOUT("KKLayout", KKLayout.class),
	SPRINGLAYOUT("SpringLayout", SpringLayout.class),
	SPRINGLAYOUT2("SpringLayout2", SpringLayout2.class);
	
	private String name;
	private Class<?> layoutClass;
	
	private LAYOUT(String name, Class<?> layoutClass){
		this.name = name;
		this.layoutClass = layoutClass;
	}
	
	public String getName(){
		return this.name;
	}
	
	public Class<?> getLayoutClass(){
		return this.layoutClass;
	}
	
	public static LAYOUT getLayoutByName(String name){
		if(name.equals(GraphFrame.FR)){
			return FRLAYOUT;
		}else if(name.equals(GraphFrame.FR2)){
			return FRLAYOUT2;
		}else if(name.equals(GraphFrame.CIRCLE)){
			return CIRCLELAYOUT;
		}else if(name.equals(GraphFrame.KK)){
			return KKLAYOUT;
		}else if(name.equals(GraphFrame.SPRING)){
			return SPRINGLAYOUT;
		}else if(name.equals(GraphFrame.SPRING2)){
			return SPRINGLAYOUT2;
		}else{
			System.err.println("Inalid Layout Name : No known Layout for the name : " + name);
			return null;
		}
	}
	
	public static Layout<VfactVertex, VfactEdge> createLayoutByName(String name, Graph<VfactVertex, VfactEdge> graph){
		if(name.equals(GraphFrame.FR)){
			return new FRLayout<VfactVertex, VfactEdge>(graph);
		}else if(name.equals(GraphFrame.FR2)){
			return new FRLayout2<VfactVertex, VfactEdge>(graph);
		}else if(name.equals(GraphFrame.CIRCLE)){
			return new CircleLayout<VfactVertex, VfactEdge>(graph);
		}else if(name.equals(GraphFrame.KK)){
			return new KKLayout<VfactVertex, VfactEdge>(graph);
		}else if(name.equals(GraphFrame.SPRING)){
			return new SpringLayout<VfactVertex, VfactEdge>(graph);
		}else if(name.equals(GraphFrame.SPRING2)){
			return new SpringLayout2<VfactVertex, VfactEdge>(graph);
		}else{
			System.err.println("Inalid Layout Name : No known Layout for the name : " + name);
			return null;
		}
	}
	
}
